<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="开通时间" align="center" prop="startDate" />
      <el-table-column label="结束时间" align="center" prop="endDate" />
      <el-table-column align="center" label="升级类型" prop="memberTypeId" width="100px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MEMBER_TERM" :value="scope.row.memberTypeId" />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
    </el-table>
    <!-- 分页 -->
    <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </ContentWrap>
</template>

<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { MemberDeadlineApi } from '@/api/wine/memberdeadline'

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: null,
  createTime: [],
  userId: null
})

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await MemberDeadlineApi.getMemberDeadlinePage(queryParams);
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}


const { userId } = defineProps({
  userId: {
    type: Number,
    required: true
  }
})

/** 初始化 **/
onMounted(() => {
  queryParams.userId = userId
  getList()
})
</script>
